﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "CmdCreateStraightStructureStripFoundation.h"
#include "GmUiStructureCommandRegister.h"
#include "StructureCmdIds.h"
#include "StructureDefaultFamilyNames.h"
#include "IUiView.h"
#include "IUiDocument.h"
#include "AddStructureDynamicPannelUtil.h"
#include "StructureInstanceEndType.h"
#include "ActionBase.h"
#include "StructureLinearInstanceCreator.h"
#include "StructureStripFoundationInput.h"
#include "StructureInstanceCmdUtils.h"
#include "GbmpBuiltInCategoryUniIdentitiesNew.h"
#include "IModelView.h"
#include "UiCommonDialog.h"
#include "GbmpModelViewTypes.h"
#include "Any.h"
#include "IActionInputEventArgs.h"
#include "UiDocumentViewUtils.h"

#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gcmp;

REGISTER_GM_COMMAND(CmdCreateStraightStructureStripFoundation)

CmdCreateStraightStructureStripFoundation::CmdCreateStraightStructureStripFoundation()
    : CmdCreateStraightStructureInstanceBase(ID_CMD_CREATE_STRAIGHT_STRUCTURE_STRIP_FOUNDATION)
{
}

StructureFamilyUiUtils::FamilyCreators CmdCreateStraightStructureStripFoundation::GetDefaultFamilyCreators()
{
    StructureFamilyUiUtils::FamilyCreators defaultFamilyCreators
    {
        { DEFAULT_STRUCTURE_RECT_STRIP_FOUNDATION_FAMILY_NAME, BuiltInStructureFamilies::CreateBuiltInRectStripFoundationFamilyDocument }
    };

    return defaultFamilyCreators;
}

std::wstring CmdCreateStraightStructureStripFoundation::GetDefaultFamilyName()
{
    return DEFAULT_STRUCTURE_RECT_STRIP_FOUNDATION_FAMILY_NAME;
}

OwnerPtr<StructureLinearInstanceInput> CmdCreateStraightStructureStripFoundation::GetInstanceInput(const std::vector<Vector3d>& pts) const
{
    IDocument* pDoc = UiDocumentViewUtils::GetCurrentDocument();
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pDoc, L"pDoc为空",L"GDMPLab",L"2024-03-30");

    IUiView* pUIView = UiDocumentViewUtils::GetCurrentUiView();
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pUIView, L"pUIView为空",L"GDMPLab",L"2024-03-30");

    OwnerPtr<StructureStripFoundationInput> foundationInput = NEW_AS_OWNER_PTR(StructureStripFoundationInput);
    foundationInput->PositionPoints = pts;

    bool bOk = StructureInstanceCmdUtils::GenerateStraightStructureStripFoundationInput(pDoc, pUIView->GetModelView(),
        this->GetCategory(), this->GetCategorySecondKey(), m_familyId, m_instanceTypeId, *foundationInput);
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(bOk, L"GenerateStraightBasicStripFoundationInput失败",L"GDMPLab",L"2024-03-30");

    return TransferOwnership(foundationInput);
}

OwnerPtr<IStructureLinearInstanceCreator> CmdCreateStraightStructureStripFoundation::GetInstanceCreator() const
{
    return NEW_AS_OWNER_PTR(StructureStraightStructureStripFoundationCreator);
}

Int32 CmdCreateStraightStructureStripFoundation::GetCategorySecondKey() const
{
    return 0;
}

void CmdCreateStraightStructureStripFoundation::SetupRibbonContextualPanel()
{
    AddStructureDynamicPannelUtil::SetupStripFoundationCreationContext(m_pAction, true, false);
}

gcmp::UniIdentity gcmp::CmdCreateStraightStructureStripFoundation::GetCategory() const
{
    UniIdentity categoryUid = BuiltInCategoryUniIdentities::BICU_STRUCTURE_STRIP_FOUNDATION;
    return categoryUid;
}

bool gcmp::CmdCreateStraightStructureStripFoundation::OnExecuteCommand() const
{
    IModelView* pModelView = UiDocumentViewUtils::GetCurrentModelView();
    DBG_WARN_AND_RETURN_NULLPTR_UNLESS(pModelView, L"pModelView为空",L"GDMPLab",L"2024-03-30");
    const std::wstring& viewType = pModelView->GetUserDataId();

    if (PlanViewType != viewType && View3DViewType != viewType)
    {
        UiCommonDialog::ShowMessageBox(GBMP_TR(L"绘制条形基础"), GBMP_TR(L"此视图下不支持绘制条形基础"), (int)UiCommonDialog::ButtonType::OK);
        return false;
    }
    return true;
}

void CmdCreateStraightStructureStripFoundation::DefineInputDialog(DefineInputDialogParams& inputItems)
{
    return;
}

void CmdCreateStraightStructureStripFoundation::OnActionInputEvent(IActionInputEventArgs* pArgs)
{
    return;
}
